<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>编辑考试</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加考试</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="" style="width: 90%">
    <input type="hidden" id="examassignmentid" name="examassignmentid" lay-verify="examassignmentid" value="<{$exam_assignment.id}>">
    <div class="layui-form-item">
        <label class="layui-form-label">试卷标题</label>
        <div class="layui-input-block ">
            <input type="text" id="examtitle" name="examtitle" lay-verify="examtitle" autocomplete="off"
                   placeholder="请输入考试标题，不填则和题库名称相同" class="layui-input" value="<{$exam_assignment.examtitle}>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">做题单位</label>
        <div class="layui-input-block ">
            <select name="unit" id="unit" lay-filter="unit" lay-verify="unit" lay-search>
                <option value="">请选择</option>
                <option <if condition="$exam_assignment.unit eq 1">selected</if> value="1">指定学生</option>
                <option <if condition="$exam_assignment.unit eq 2">selected</if> value="2">指定年级</option>
                <option <if condition="$exam_assignment.unit eq 3">selected</if> value="3">所有学生</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item ">
        <label class="layui-form-label">做题时长</label>
        <div class="layui-input-block ">
            <input type="number" id="duration" name="duration" lay-verify="duration" autocomplete="off"
                   placeholder="时间(分钟)" class="layui-input" value="<{$exam_assignment.duration}>">
        </div>
    </div>
    <div class="layui-form-item" >
        <div class="layui-inline" pane>
            <label class="layui-form-label">做题次数</label>
            <div class="layui-input-inline " style="width: 226px;">
                <input type="radio" lay-verify="is_frequency_restrict" lay-filter="is_frequency_restrict" name="is_frequency_restrict" value="0"
                       title="无限制" <if condition="$exam_assignment.is_frequency_restrict eq 0">checked</if>>
                <input type="radio" lay-verify="is_frequency_restrict" lay-filter="is_frequency_restrict" name="is_frequency_restrict" value="1"
                       title="指定" <if condition="$exam_assignment.is_frequency_restrict eq 1">checked</if>>
            </div>
            <label class="layui-form-label">做题次数</label>
            <div class="layui-input-inline" style="width: 150px;" >
                <input type="number" id="MaxFrequency" name="MaxFrequency" lay-verify="MaxFrequency" autocomplete="off"
                       placeholder="<if condition="$exam_assignment.is_frequency_restrict eq 1">最大做题次数(填写数字)<else />无限制</if>" class="layui-input" value="<if condition="$exam_assignment.is_frequency_restrict eq 1"><{$exam_assignment.max_frequency}><else /></if>"
                 <if condition="$exam_assignment.is_frequency_restrict eq 0">disabled</if> >
            </div>
        </div>
    </div>
    <div class="layui-form-item " pane>
        <label class="layui-form-label">时间设置</label>
        <div class="layui-input-block ">
            <input type="radio" lay-verify="is_startfinish" lay-filter="is_startfinish" name="is_startfinish" value="0"
                   title="无限制" <if condition="$exam_assignment.is_startfinish eq 0">checked</if> >
            <input type="radio" lay-verify="is_startfinish" lay-filter="is_startfinish" name="is_startfinish" value="1"
                   title="设置时间" <if condition="$exam_assignment.is_startfinish eq 1">checked</if>>
        </div>
    </div>
    <div id="startfinish_id" class="layui-form-item"  <if condition="$exam_assignment.is_startfinish eq 0">style="display: none;"</if> >
        <label class="layui-form-label">时间范围</label>
        <div class="layui-input-block ">
            <input type="text" id="startfinish" name="startfinish" lay-verify="startfinish" autocomplete="off"
                   placeholder="输选择时间范围" class="layui-input" value="<{$exam_assignment.values}>">
        </div>
    </div>
    <div class="layui-form-item " pane>
        <div class="layui-inline">
            <label class="layui-form-label">评语类型</label>
            <div class="layui-input-block">
                <input type="radio" name="commentType" value="0" title="手动设置" <if condition="$exam_assignment.comment_type eq 0">checked</if> >
                <input type="radio" name="commentType" value="1" title="AI分析" <if condition="$exam_assignment.comment_type eq 1">checked</if> disabled>
            </div>
        </div>
    </div>
    <div class="layui-form-item" pane>
        <div class="layui-inline">
            <label class="layui-form-label">评分方式</label>
            <div class="layui-input-block">
                <input type="radio" name="GradingType" value="0" title="考完后立即评分" <if condition="$exam_assignment.grading_type eq 0">checked</if> >
                <input type="radio" name="GradingType" value="1" title="老师确认后评分" <if condition="$exam_assignment.grading_type eq 1">checked</if> >
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script type="text/javascript" src="__PUBLIC__/BeginnerAdmin/plugins/layui/layui.js"></script>
<script type="text/javascript" src="__PUBLIC__/AmazeUI/assets/js/jquery-1.8.0.min.js"></script>
<script>
    function settime() {
        var index=parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);

    }

    layui.use(['form','laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate
        ;
        laydate.render({
            elem: '#startfinish'
            ,type: 'datetime'
            ,range: true
            ,range:'-'
            ,max:'2038-1-18'
            ,format: 'yyyy/M/d HH:mm:ss'
            ,value:'<{$exam_assignment.values}>'
        });
        //自定义验证规则
        form.verify({
            examtitle: function (value) {
                if(value == null || value == ''){
                    return '标题必须填写';
                }
            },
            unit: function (value) {
                if (value == null || value == '') {
                    return '做题单位必须设置';
                }
            },
            MaxFrequency: function (value) {
                if (value == null || value == '') {
                    if($('input[name="is_frequency_restrict"]:checked').val() == 1 || $('input[name="is_frequency_restrict"]:checked').val() == '1'){
                        return '最多做题次数必须填写';
                    }
                }
            },
            duration: function (value) {
                if (value < 1) {
                    return '时间必须设置，并且大于1分钟';
                }
            },
            startfinish: function (value) {
                if ($("input[name='is_startfinish']:checked").val() == '1' || $("input[name='is_startfinish']:checked").val() == 1) {
                    if (value.length == '') {
                        return '考试时间范围必须设置';
                    }
                }

            }
        });

        form.on('radio(is_startfinish)', function (data) {
            console.log(data); //得到radio原始DOM对象
            console.log(data.elem); //得到radio原始DOM对象
            console.log(data.value); //被点击的radio的value值
            if (data.value == 1 || data.value == '1') {
                $("#startfinish_id").show();
            } else {
                $("#startfinish_id").hide();
            }
        });
        form.on('radio(is_frequency_restrict)',function (data) {
            if (data.value == 1 || data.value == '1'){
                $("#MaxFrequency").removeAttr('disabled');//placeholder="最大做题次数(填写数字)"
                $("#MaxFrequency").attr('placeholder','最大做题次数(数字)');
            }else{
                $("#MaxFrequency").attr('placeholder','无限制');
                $("#MaxFrequency").attr('disabled','disabled');
                $("#MaxFrequency").val('');

            }
        });
        //监听提交
        form.on('submit(demo1)', function(data) {
            $.post('Admin_Paper_EditPaper.html',data.field,function (ret) {
                if(ret.code == 200){
                    layer.msg('修改成功');
                    setTimeout('settime()', 1500);//延时执行，让人看得更清楚
                }else{
                    layer.alert(ret.msg);
                }
            },'json');
            return false;
        });
    });
    $(document).ready(function(){
        $('#startfinish').trigger('click');
    });
</script>
</body>
</html>